<!DOCTYPE html>
<html>
<body>
 
<div id="capture" style="width: 200px; height: 200px; background-color: #f90;">
  这里是你想要截图的内容
</div>
 
<button onclick="captureElement()">截图并下载</button>
 
<script>
function captureElement() {
  html2canvas(document.querySelector("#capture")).then(canvas => {
    // 创建一个图片元素
    var img = canvas.toDataURL("image/png");
    // 创建一个链接元素
    var link = document.createElement('a');
    // 设置下载属性
    link.href = img;
    link.download = 'screenshot.png';
    // 触发点击
    link.click();
  });
}
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/1.3.2/html2canvas.min.js"></script>
 
</body>
</html>